//
//  RBGoodsEvaluateListHeaderView.m
//  zhongzhenglu
//
//  Created by 马军凯 on 2023/5/9.
//

#import "RBGoodsEvaluateListHeaderView.h"

@interface RBGoodsEvaluateListHeaderView ()
//全部
@property (weak, nonatomic) IBOutlet UIButton *allBtn;

@property (weak, nonatomic) IBOutlet UIButton *goodBtn;

@property (weak, nonatomic) IBOutlet UIButton *middleBtn;
@property (weak, nonatomic) IBOutlet UIButton *badBtn;

@end

@implementation RBGoodsEvaluateListHeaderView

- (void)awakeFromNib {
    [super awakeFromNib];
    //
    [self initBtnWith:self.allBtn];
}
//赋值
- (void)setModel:(RBGoodsEvaluateListModel *)model {
    _model = model;
    //全部
    [self.allBtn setTitle:[NSString stringWithFormat:@"全部(%@)", model.total] forState:UIControlStateNormal];
    
    [self.goodBtn setTitle:[NSString stringWithFormat:@"好评(%@)", model.best] forState:UIControlStateNormal];
    
    [self.middleBtn setTitle:[NSString stringWithFormat:@"中评(%@)", model.just] forState:UIControlStateNormal];
    
    [self.badBtn setTitle:[NSString stringWithFormat:@"差评(%@)", model.bed] forState:UIControlStateNormal];
}

- (IBAction)clickBtn:(UIButton *)sender {
    [self initBtnWith:sender];
    
    NSString *type = @"-1";
    if (sender == self.allBtn) {
        type = @"-1";
    } else if (sender == self.goodBtn) {
        type = @"1";
    } else if (sender == self.middleBtn) {
        type = @"2";
    } else if (sender == self.badBtn) {
        type = @"3";
    }
    
    if (self.block) {
        self.block(type);
    }
}

//按钮
- (void)initBtnWith:(UIButton *)sender {
    NSArray *btnArray = @[self.allBtn, self.goodBtn, self.middleBtn, self.badBtn];
    for (UIButton *btn in btnArray) {
        btn.backgroundColor = [[UIColor LC_hex:@"#518CFF"] colorWithAlphaComponent:0.15];
        [btn setTitleColor:[UIColor LC_hex:@"#333333"] forState:UIControlStateNormal];
    }
    sender.backgroundColor = [UIColor LC_hex:@"#518CFF"];
    [sender setTitleColor:[UIColor LC_hex:@"#FFFFFF"] forState:UIControlStateNormal];
}

@end
